package com.gx.ObserverPattern.java;

import com.gx.ObserverPattern.DisplayElement;

import java.util.Observable;
import java.util.Observer;

/**
 * Created by gx on 2017/3/1.
 */
public class CurrentConditionsDisplay implements Observer ,DisplayElement{

    Observable observable;
    private float temperature;
    private float humidity;

    public CurrentConditionsDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof  WeatherData){
            WeatherData weatherData = (WeatherData)o;
            this.temperature=weatherData.getTemperature();
            this.humidity=weatherData.getHumidity();
            display();
        }
    }

    @Override
    public void display() {
        System.out.println("Current conditions:"+temperature+"F degress and " + humidity +"% humidity");
    }
}
